<?php

class MDPacksDraw
{

public static $instance; 

public static function getInstance()
	{
		//echo "<div id=register-box>";
        if(self::$instance==null)
		  self::$instance=new MDPacksDraw();
	//   echo "</div>";	  
		return  self::$instance;
	   
    
    }	

function DrawTable($title,$table,$campos,$filter)//obligatorio ID como campo inicial
    {
 
 
     $qu="select ";
    $i = 0;
    $i = 0;
    foreach($campos as $id=>$valor)
    {
    $qu=$qu."$id,";


    }
    $qu=substr($qu,0,strlen($qu)-1);
    $qu=$qu." from "."$table";
    
    if($filter!=""){
        $qu = $qu." $filter";
        //echo $qu;
    }
     echo "<div id='content_area_user_title'>";
    echo "<h2> $title</h2>";
    echo "</div>";


    echo	"<form>";						
    echo "<form id='filter-form'>Filtrar operador: <input name='filter' id='filter' value='' maxlength='30' size='30' type='text'></form><br>";
    echo "</form>";
   
    echo "<div class='usersettings_statistics'>"; 
 


    echo "<table class='food_planner'>";
    
     echo "<thead>";
    echo "<tr>";
      //$width=10;    
     foreach($campos as $id=>$valor){
    
    echo "<th>$valor</th>";
    //$width=$width+10;
    }
    echo "<th>Operador</th>";
    echo "<th>Sede</th>";
    echo "<th>Itinerario</th>";
    echo "<th>Tours</th>";    
    echo "<th>E</th>";
    echo "<th>X</th>";
    
    echo "</tr>";    
    echo "</thead>";
    
    
    echo "<tbody><tr style='display: table-row;'>";

     //echo "<table> <tbody>";

    
     
    
    
 //echo "<tr class='odd'>";
    
    // $qu="select*from $table";
    $table=CModelo::getInstance()->getData($qu);
//var_dump($table);
    $cont=0;
    
    $ruta=CConfig::getInstance()->rutalocal;
    

    foreach($table as $campo => $valor)
    { 



$cont=$cont+1;
if($cont%2){


echo "<tr class='odd'>";
$i="";$cont=0;
foreach($valor as $id=>$val)
{ if($cont==0){$i=$val;}

echo "<td>$val</td>";$cont=$cont+1;
}

$query = "SELECT  `operador`.`NamOpe` ,  `oficinas`.`idOfi` ,  `oficinas`.`OPERADOR_idOpe` ,  `pack`.`OFICINAS_idOfi` ,  `pack`.`idPack`, `pack`.`AvaPack`, `oficinas`.`DirOfi`  
FROM operador LEFT JOIN  `viv`.`oficinas` ON  `operador`.`idOpe` =  `oficinas`.`OPERADOR_idOpe` LEFT JOIN  `viv`.`pack` ON  `oficinas`.`idOfi` =  `pack`.`OFICINAS_idOfi` WHERE ((idPack =$i))";


$result = CModelo::getInstance()->getData($query);
foreach($result as $r=>$c){
    $table1 = $c;
    foreach($table1 as $r1 => $c1){
        $operador[] = $c1;
    }
}


$k = CTourEditDraw::getInstance()->getDefaultTour("pack_has_tour","PACK_idPack",$i,"idPackTour");
    


/*---------------------------------------------------------------------------*/
// las referencias debbden de ser modificadas deacuerdo al directorio
//
/*---------------------------------------------------------------------------*/

echo "<td><a href='$ruta/index.php?idOpe=$operador[2]'> $operador[0] </a> </td>";
echo "<td><a href='$ruta/index.php?idOfi=$operador[1]'> $operador[6] </a> </td>";
echo "<td> <input type=button onClick=\"parent.location='$ruta/MDItinerary/MDEItinerary.php?codigo=$k'\" value='Itinerario del paquete $i'>  </td>";
echo "<td> <input type=button onClick=\"parent.location='$ruta/MDTourGeneral/CTourEdit.php?codigo=$i&tourcreate=1'\" value='Crear tour'>  </td>";
echo "<td> <a href='$ruta/MDTourGeneral/CTourEdit.php?codigo=$i&default=0'> <img src='../MDTour/images/edit.png' width='32' title='Editar operador $i'/></a> </td>";
echo "<td><a href='/christian1/modificar.php?codigo=$i'> <img src='../MDTour/images/trash.png' width='32' title='Eliminar operador $i'/> </a> </td>";
echo "</tr>";

$operador="";
}
else
{
$url="asf";
echo "<tr class='even'> ";
$i2="";$cont2=0;
foreach($valor as $id => $val)
{ if($cont2==0){$i2=$val;}
echo "<td>$val </td>";$cont2=$cont2+1;
}
echo "<td> <a href='$ruta/MDTourGeneral/CTourEdit.php?codigo=$i2&default=0'>Editar</a> </td>";
echo "<td><a href='/christian1/modificar.php?codigo=$i2'>Eliminar</a> </td>";
echo "<td> <input type=button onClick=\"parent.location='$ruta/MDTourGeneral/CTourEdit.php?codigo=$i2&default=1'\" value='Crear tour'>  </td>";
echo "</tr>";
}

}
echo "</td></tr></tbody></table><br><br>";


echo "</div>";

} 



}
?>